<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('扫描批次信息')" />
    <th:block th:include="include :: datetimepicker-css" />

</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <h3>扫描批次信息</h3>
    <form class="form-horizontal m" id="scanBatchInfoForm">
        <div class="form-group">
            <label>交易日期：</label>
            <div class=" date">
                <input id="trDate" name="trDate" class="form-control" placeholder="yyyy-MM-dd" type="text" readonly="true" required>
            </div>
        </div>
        <div class="form-group">
            <label>交易机构：</label>
            <div class="">
                <input id="orgCode" name="orgCode" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label>柜员号：</label>
            <div class="">
                <input id="tellerCode" name="tellerCode" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label>扫描张数：</label>
            <div class="">
                <input id="fileNum" name="fileNum" class="form-control" type="text" required>
            </div>
        </div>
        <input id="scanType" name="scanType" class="form-control" type="hidden" value="0">
        <div>
            <button type="button" class="btn btn-sm btn-primary" onclick="checkInput()"><i class="fa fa-check"></i>开始扫描</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="scanWorkload()"><i class="fa fa-reply-all"></i>当日张数</button>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script type="text/javascript">
    var prefix = '/sdi/scan';

    $("input[name='trDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("#scanBatchInfoForm").validate({
        onkeyup: false,
        rules:{
            trDate: {
              required: true
            },
            orgCode:{
                required: true,
                rangelength: [5,5],
                remote: {
                    url: prefix+"/checkOrgCodeExists",
                    type: "post",
                    dataType: "json",
                    data: {
                        "orgCode" : function() {
                            return $.common.trim($("#orgCode").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            tellerCode: {
                required: true,
                rangelength: [7,7]
            }
        },
        messages: {
            "orgCode": {
                remote: "机构号不存在"
            }
        }/*,
        showErrors: function(errorMap, errorList) {
            this.defaultShowErrors();
            for(var i = 0; i < errorList.length; i++) {
                $(errorList[i].element).one("blur", function() {
                    $("label.error[for='" + (this.id ? this.id : this.name) + "']").remove();
                });
            }
        }*/,
        focusCleanup: true
    });

    //验证扫描填写信息
    function checkInput() {
        if ($.validate.form()) {
            var data =$('#scanBatchInfoForm').serialize();
            $.operate.post(prefix+'/checkBatchScannable',data,function (result) {
                if(result.code ==web_status.SUCCESS){
                    var v_checkNum = result.data.registerNum;
                    var v_pageCount = $("#fileNum").val();
                    if(v_checkNum!=v_pageCount){
                        if(confirm("网点登记张数"+v_checkNum +"与你输入的张数"+v_pageCount+"不符合,是否继续？")==false) {
                            $("#fileNum").focus().select();
                            return false;
                        }
                    }
                    var ssoOrgCode = result.data.ssoOrgCode;
                    var v_subPath = result.data.subPath;
                    var v_TrDate = $("#trDate").val();
                    var v_OrgCode = $("#orgCode").val();
                    var trTelr = $("#tellerCode").val();
                    var year = v_TrDate.substring(0,4);
                    var month =  v_TrDate.substring(0,4)+v_TrDate.substring(5,7);
                    var date = v_TrDate.substring(0,4)+v_TrDate.substring(5,7)+v_TrDate.substring(8,10);
                    var submitUrlArgs ="&trDate="+v_TrDate+"&tellerCode="+trTelr+"&orgCode="+v_OrgCode;
                    var v_LocalPath = 'C:/northking/orms/scannedfile'+ "/" + date +"/"+v_OrgCode+ "/" + trTelr;
                    var v_ftpPath = "/" +year+"/" + month+"/" + date +"/"+ssoOrgCode+ "/"+ v_OrgCode+ "/" + trTelr + "/" + v_subPath;
                    var v_otherMsg =  " 扫描信息【业务日期：" + date +"  机构:"+v_OrgCode
                        + "   柜员：" + trTelr
                        + "    扫描张数：" + v_pageCount + "】";
                    window.returnValue = submitUrlArgs
                        + "@@@" + v_LocalPath
                        + "@@@" + ""
                        + "@@@" + v_ftpPath
                        + "@@@" + v_pageCount
                        + "@@@" + v_otherMsg
                        + "@@@" + v_checkNum
                        + "@@@" + v_TrDate
                        + "@@@" + "0";
                    window.close();
                } else {
                    $.modal.msgError(result.msg);
                }

            })
        }
    }

    //获取扫描员当日工作量
    function scanWorkload() {
        $.operate.get(prefix+'/scanWorkload');
    }
</script>
</body>
</html>